{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4b8a3be8",
   "metadata": {
    "papermill": {
     "duration": 0.005007,
     "end_time": "2025-02-15T10:13:17.449343",
     "exception": false,
     "start_time": "2025-02-15T10:13:17.444336",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "**This notebook is an exercise in the [Introduction to Machine Learning](https://www.kaggle.com/learn/intro-to-machine-learning) course.  You can reference the tutorial at [this link](https://www.kaggle.com/dansbecker/your-first-machine-learning-model).**\n",
    "\n",
    "---\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "909eb25f",
   "metadata": {
    "papermill": {
     "duration": 0.004071,
     "end_time": "2025-02-15T10:13:17.458109",
     "exception": false,
     "start_time": "2025-02-15T10:13:17.454038",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Recap\n",
    "So far, you have loaded your data and reviewed it with the following code. Run this cell to set up your coding environment where the previous step left off."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "90872a2d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T10:13:17.468328Z",
     "iopub.status.busy": "2025-02-15T10:13:17.467955Z",
     "iopub.status.idle": "2025-02-15T10:13:20.455079Z",
     "shell.execute_reply": "2025-02-15T10:13:20.453654Z"
    },
    "papermill": {
     "duration": 2.995124,
     "end_time": "2025-02-15T10:13:20.457646",
     "exception": false,
     "start_time": "2025-02-15T10:13:17.462522",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Setup Complete\n"
     ]
    }
   ],
   "source": [
    "# Code you have previously used to load data\n",
    "import pandas as pd\n",
    "\n",
    "# Path of the file to read\n",
    "iowa_file_path = '../input/home-data-for-ml-course/train.csv'\n",
    "\n",
    "home_data = pd.read_csv(iowa_file_path)\n",
    "\n",
    "# Set up code checking\n",
    "from learntools.core import binder\n",
    "binder.bind(globals())\n",
    "from learntools.machine_learning.ex3 import *\n",
    "\n",
    "print(\"Setup Complete\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f447444e",
   "metadata": {
    "papermill": {
     "duration": 0.004297,
     "end_time": "2025-02-15T10:13:20.466739",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.462442",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Exercises\n",
    "\n",
    "## Step 1: Specify Prediction Target\n",
    "Select the target variable, which corresponds to the sales price. Save this to a new variable called `y`. You'll need to print a list of the columns to find the name of the column you need.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "df442fab",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T10:13:20.477213Z",
     "iopub.status.busy": "2025-02-15T10:13:20.476635Z",
     "iopub.status.idle": "2025-02-15T10:13:20.484270Z",
     "shell.execute_reply": "2025-02-15T10:13:20.483152Z"
    },
    "papermill": {
     "duration": 0.014952,
     "end_time": "2025-02-15T10:13:20.486213",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.471261",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Id', 'MSSubClass', 'MSZoning', 'LotFrontage', 'LotArea', 'Street',\n",
       "       'Alley', 'LotShape', 'LandContour', 'Utilities', 'LotConfig',\n",
       "       'LandSlope', 'Neighborhood', 'Condition1', 'Condition2', 'BldgType',\n",
       "       'HouseStyle', 'OverallQual', 'OverallCond', 'YearBuilt', 'YearRemodAdd',\n",
       "       'RoofStyle', 'RoofMatl', 'Exterior1st', 'Exterior2nd', 'MasVnrType',\n",
       "       'MasVnrArea', 'ExterQual', 'ExterCond', 'Foundation', 'BsmtQual',\n",
       "       'BsmtCond', 'BsmtExposure', 'BsmtFinType1', 'BsmtFinSF1',\n",
       "       'BsmtFinType2', 'BsmtFinSF2', 'BsmtUnfSF', 'TotalBsmtSF', 'Heating',\n",
       "       'HeatingQC', 'CentralAir', 'Electrical', '1stFlrSF', '2ndFlrSF',\n",
       "       'LowQualFinSF', 'GrLivArea', 'BsmtFullBath', 'BsmtHalfBath', 'FullBath',\n",
       "       'HalfBath', 'BedroomAbvGr', 'KitchenAbvGr', 'KitchenQual',\n",
       "       'TotRmsAbvGrd', 'Functional', 'Fireplaces', 'FireplaceQu', 'GarageType',\n",
       "       'GarageYrBlt', 'GarageFinish', 'GarageCars', 'GarageArea', 'GarageQual',\n",
       "       'GarageCond', 'PavedDrive', 'WoodDeckSF', 'OpenPorchSF',\n",
       "       'EnclosedPorch', '3SsnPorch', 'ScreenPorch', 'PoolArea', 'PoolQC',\n",
       "       'Fence', 'MiscFeature', 'MiscVal', 'MoSold', 'YrSold', 'SaleType',\n",
       "       'SaleCondition', 'SalePrice'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# print the list of columns in the dataset to find the name of the prediction target\n",
    "home_data.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b247b427",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T10:13:20.497387Z",
     "iopub.status.busy": "2025-02-15T10:13:20.497001Z",
     "iopub.status.idle": "2025-02-15T10:13:20.510610Z",
     "shell.execute_reply": "2025-02-15T10:13:20.509478Z"
    },
    "papermill": {
     "duration": 0.020918,
     "end_time": "2025-02-15T10:13:20.512299",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.491381",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"outcomeType\": 1, \"valueTowardsCompletion\": 0.25, \"interactionType\": 1, \"questionType\": 2, \"questionId\": \"1_SetTarget\", \"learnToolsVersion\": \"0.3.4\", \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\"}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc33\">Correct</span>"
      ],
      "text/plain": [
       "Correct"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "y = home_data.SalePrice\n",
    "\n",
    "# Check your answer\n",
    "step_1.check()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "39a49fc3",
   "metadata": {
    "papermill": {
     "duration": 0.004963,
     "end_time": "2025-02-15T10:13:20.522186",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.517223",
     "status": "completed"
    },
    "tags": []
   },
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6538670a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T10:13:20.533254Z",
     "iopub.status.busy": "2025-02-15T10:13:20.532710Z",
     "iopub.status.idle": "2025-02-15T10:13:20.544211Z",
     "shell.execute_reply": "2025-02-15T10:13:20.543229Z"
    },
    "papermill": {
     "duration": 0.018909,
     "end_time": "2025-02-15T10:13:20.545973",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.527064",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 2, \"questionType\": 2, \"questionId\": \"1_SetTarget\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#3366cc\">Hint:</span> Use `print(home_data.columns)`. The column you want is at the end of the list. Use the dot notation to pull out this column from the DataFrame"
      ],
      "text/plain": [
       "Hint: Use `print(home_data.columns)`. The column you want is at the end of the list. Use the dot notation to pull out this column from the DataFrame"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 3, \"questionType\": 2, \"questionId\": \"1_SetTarget\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc99\">Solution:</span> \n",
       "```python\n",
       "y = home_data.SalePrice\n",
       "```"
      ],
      "text/plain": [
       "Solution: \n",
       "```python\n",
       "y = home_data.SalePrice\n",
       "```"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# The lines below will show you a hint or the solution.\n",
    "step_1.hint() \n",
    "step_1.solution()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4749a339",
   "metadata": {
    "papermill": {
     "duration": 0.00497,
     "end_time": "2025-02-15T10:13:20.556501",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.551531",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Step 2: Create X\n",
    "Now you will create a DataFrame called `X` holding the predictive features.\n",
    "\n",
    "Since you want only some columns from the original data, you'll first create a list with the names of the columns you want in `X`.\n",
    "\n",
    "You'll use just the following columns in the list (you can copy and paste the whole list to save some typing, though you'll still need to add quotes):\n",
    "  * LotArea\n",
    "  * YearBuilt\n",
    "  * 1stFlrSF\n",
    "  * 2ndFlrSF\n",
    "  * FullBath\n",
    "  * BedroomAbvGr\n",
    "  * TotRmsAbvGrd\n",
    "\n",
    "After you've created that list of features, use it to create the DataFrame that you'll use to fit the model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e5a37fed",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T10:13:20.568289Z",
     "iopub.status.busy": "2025-02-15T10:13:20.567892Z",
     "iopub.status.idle": "2025-02-15T10:13:20.580667Z",
     "shell.execute_reply": "2025-02-15T10:13:20.579339Z"
    },
    "papermill": {
     "duration": 0.0209,
     "end_time": "2025-02-15T10:13:20.582593",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.561693",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"outcomeType\": 1, \"valueTowardsCompletion\": 0.25, \"interactionType\": 1, \"questionType\": 2, \"questionId\": \"2_SelectPredictionData\", \"learnToolsVersion\": \"0.3.4\", \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\"}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc33\">Correct</span>"
      ],
      "text/plain": [
       "Correct"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Create the list of features below\n",
    "feature_names = ['LotArea','LotArea','1stFlrSF','2ndFlrSF','FullBath','BedroomAbvGr','TotRmsAbvGrd']\n",
    "\n",
    "# Select data corresponding to features in feature_names\n",
    "X = home_data[feature_names]\n",
    "\n",
    "# Check your answer\n",
    "step_2.check()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "aac3fd64",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T10:13:20.595456Z",
     "iopub.status.busy": "2025-02-15T10:13:20.595048Z",
     "iopub.status.idle": "2025-02-15T10:13:20.606388Z",
     "shell.execute_reply": "2025-02-15T10:13:20.605022Z"
    },
    "papermill": {
     "duration": 0.019889,
     "end_time": "2025-02-15T10:13:20.608408",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.588519",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 2, \"questionType\": 2, \"questionId\": \"2_SelectPredictionData\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#3366cc\">Hint:</span> Capitalization and spelling are important when specifying variable names. Use the brackets notation when specifying data for X."
      ],
      "text/plain": [
       "Hint: Capitalization and spelling are important when specifying variable names. Use the brackets notation when specifying data for X."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 3, \"questionType\": 2, \"questionId\": \"2_SelectPredictionData\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc99\">Solution:</span> \n",
       "```python\n",
       "feature_names = [\"LotArea\", \"YearBuilt\", \"1stFlrSF\", \"2ndFlrSF\",\n",
       "                      \"FullBath\", \"BedroomAbvGr\", \"TotRmsAbvGrd\"]\n",
       "\n",
       "X=home_data[feature_names]\n",
       "```"
      ],
      "text/plain": [
       "Solution: \n",
       "```python\n",
       "feature_names = [\"LotArea\", \"YearBuilt\", \"1stFlrSF\", \"2ndFlrSF\",\n",
       "                      \"FullBath\", \"BedroomAbvGr\", \"TotRmsAbvGrd\"]\n",
       "\n",
       "X=home_data[feature_names]\n",
       "```"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "step_2.hint()\n",
    "step_2.solution()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa784b8b",
   "metadata": {
    "papermill": {
     "duration": 0.005562,
     "end_time": "2025-02-15T10:13:20.620206",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.614644",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Review Data\n",
    "Before building a model, take a quick look at **X** to verify it looks sensible"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "206918f2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T10:13:20.633715Z",
     "iopub.status.busy": "2025-02-15T10:13:20.633295Z",
     "iopub.status.idle": "2025-02-15T10:13:20.672617Z",
     "shell.execute_reply": "2025-02-15T10:13:20.671127Z"
    },
    "papermill": {
     "duration": 0.048453,
     "end_time": "2025-02-15T10:13:20.674588",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.626135",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             LotArea        LotArea     1stFlrSF     2ndFlrSF     FullBath  \\\n",
      "count    1460.000000    1460.000000  1460.000000  1460.000000  1460.000000   \n",
      "mean    10516.828082   10516.828082  1162.626712   346.992466     1.565068   \n",
      "std      9981.264932    9981.264932   386.587738   436.528436     0.550916   \n",
      "min      1300.000000    1300.000000   334.000000     0.000000     0.000000   \n",
      "25%      7553.500000    7553.500000   882.000000     0.000000     1.000000   \n",
      "50%      9478.500000    9478.500000  1087.000000     0.000000     2.000000   \n",
      "75%     11601.500000   11601.500000  1391.250000   728.000000     2.000000   \n",
      "max    215245.000000  215245.000000  4692.000000  2065.000000     3.000000   \n",
      "\n",
      "       BedroomAbvGr  TotRmsAbvGrd  \n",
      "count   1460.000000   1460.000000  \n",
      "mean       2.866438      6.517808  \n",
      "std        0.815778      1.625393  \n",
      "min        0.000000      2.000000  \n",
      "25%        2.000000      5.000000  \n",
      "50%        3.000000      6.000000  \n",
      "75%        3.000000      7.000000  \n",
      "max        8.000000     14.000000  \n",
      "   LotArea  LotArea  1stFlrSF  2ndFlrSF  FullBath  BedroomAbvGr  TotRmsAbvGrd\n",
      "0     8450     8450       856       854         2             3             8\n",
      "1     9600     9600      1262         0         2             3             6\n",
      "2    11250    11250       920       866         2             3             6\n",
      "3     9550     9550       961       756         1             3             7\n",
      "4    14260    14260      1145      1053         2             4             9\n"
     ]
    }
   ],
   "source": [
    "# Review data\n",
    "# print description or statistics from X\n",
    "print(X.describe())\n",
    "\n",
    "# print the top few lines\n",
    "print(X.head())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "391bcc79",
   "metadata": {
    "papermill": {
     "duration": 0.006288,
     "end_time": "2025-02-15T10:13:20.687265",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.680977",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Step 3: Specify and Fit Model\n",
    "Create a `DecisionTreeRegressor` and save it iowa_model. Ensure you've done the relevant import from sklearn to run this command.\n",
    "\n",
    "Then fit the model you just created using the data in `X` and `y` that you saved above."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "626e9617",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T10:13:20.700869Z",
     "iopub.status.busy": "2025-02-15T10:13:20.700461Z",
     "iopub.status.idle": "2025-02-15T10:13:20.721335Z",
     "shell.execute_reply": "2025-02-15T10:13:20.720237Z"
    },
    "papermill": {
     "duration": 0.029881,
     "end_time": "2025-02-15T10:13:20.723237",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.693356",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"outcomeType\": 1, \"valueTowardsCompletion\": 0.25, \"interactionType\": 1, \"questionType\": 2, \"questionId\": \"3_CreateModel\", \"learnToolsVersion\": \"0.3.4\", \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\"}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc33\">Correct</span>"
      ],
      "text/plain": [
       "Correct"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# from _ import _\n",
    "from sklearn.tree import DecisionTreeRegressor\n",
    "#specify the model. \n",
    "#For model reproducibility, set a numeric value for random_state when specifying the model\n",
    "iowa_model = DecisionTreeRegressor(random_state=1)\n",
    "\n",
    "# Fit the model\n",
    "iowa_model.fit(X,y)\n",
    "\n",
    "# Check your answer\n",
    "step_3.check()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "45db20e1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T10:13:20.737514Z",
     "iopub.status.busy": "2025-02-15T10:13:20.737173Z",
     "iopub.status.idle": "2025-02-15T10:13:20.748835Z",
     "shell.execute_reply": "2025-02-15T10:13:20.747709Z"
    },
    "papermill": {
     "duration": 0.020611,
     "end_time": "2025-02-15T10:13:20.750495",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.729884",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 2, \"questionType\": 2, \"questionId\": \"3_CreateModel\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#3366cc\">Hint:</span> Include `random_state` when specifying model. Data is specified when fitting it."
      ],
      "text/plain": [
       "Hint: Include `random_state` when specifying model. Data is specified when fitting it."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 3, \"questionType\": 2, \"questionId\": \"3_CreateModel\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc99\">Solution:</span> \n",
       "```python\n",
       "from sklearn.tree import DecisionTreeRegressor\n",
       "iowa_model = DecisionTreeRegressor(random_state=1)\n",
       "iowa_model.fit(X, y)\n",
       "```"
      ],
      "text/plain": [
       "Solution: \n",
       "```python\n",
       "from sklearn.tree import DecisionTreeRegressor\n",
       "iowa_model = DecisionTreeRegressor(random_state=1)\n",
       "iowa_model.fit(X, y)\n",
       "```"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "step_3.hint()\n",
    "step_3.solution()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1686cae1",
   "metadata": {
    "papermill": {
     "duration": 0.006367,
     "end_time": "2025-02-15T10:13:20.763890",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.757523",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Step 4: Make Predictions\n",
    "Make predictions with the model's `predict` command using `X` as the data. Save the results to a variable called `predictions`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f4425b03",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T10:13:20.779394Z",
     "iopub.status.busy": "2025-02-15T10:13:20.779055Z",
     "iopub.status.idle": "2025-02-15T10:13:20.792201Z",
     "shell.execute_reply": "2025-02-15T10:13:20.791271Z"
    },
    "papermill": {
     "duration": 0.023386,
     "end_time": "2025-02-15T10:13:20.794038",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.770652",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[208500. 181500. 223500. ... 266500. 142125. 147500.]\n"
     ]
    },
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"outcomeType\": 1, \"valueTowardsCompletion\": 0.25, \"interactionType\": 1, \"questionType\": 2, \"questionId\": \"4_MakePredictions\", \"learnToolsVersion\": \"0.3.4\", \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\"}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc33\">Correct</span>"
      ],
      "text/plain": [
       "Correct"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "predictions = iowa_model.predict(X)\n",
    "print(predictions)\n",
    "\n",
    "# Check your answer\n",
    "step_4.check()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "5db12f11",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T10:13:20.809707Z",
     "iopub.status.busy": "2025-02-15T10:13:20.809366Z",
     "iopub.status.idle": "2025-02-15T10:13:20.820324Z",
     "shell.execute_reply": "2025-02-15T10:13:20.819066Z"
    },
    "papermill": {
     "duration": 0.021148,
     "end_time": "2025-02-15T10:13:20.822513",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.801365",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 2, \"questionType\": 2, \"questionId\": \"4_MakePredictions\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#3366cc\">Hint:</span> Use `iowa_model.predict` with an argument holding the data to predict with."
      ],
      "text/plain": [
       "Hint: Use `iowa_model.predict` with an argument holding the data to predict with."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 3, \"questionType\": 2, \"questionId\": \"4_MakePredictions\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc99\">Solution:</span> \n",
       "```python\n",
       "iowa_model.predict(X)\n",
       "```"
      ],
      "text/plain": [
       "Solution: \n",
       "```python\n",
       "iowa_model.predict(X)\n",
       "```"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "step_4.hint()\n",
    "step_4.solution()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f69a8c68",
   "metadata": {
    "papermill": {
     "duration": 0.007529,
     "end_time": "2025-02-15T10:13:20.837622",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.830093",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Think About Your Results\n",
    "\n",
    "Use the `head` method to compare the top few predictions to the actual home values (in `y`) for those same homes. Anything surprising?\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0c46c6b7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T10:13:20.853774Z",
     "iopub.status.busy": "2025-02-15T10:13:20.853348Z",
     "iopub.status.idle": "2025-02-15T10:13:20.862360Z",
     "shell.execute_reply": "2025-02-15T10:13:20.860716Z"
    },
    "papermill": {
     "duration": 0.019581,
     "end_time": "2025-02-15T10:13:20.864441",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.844860",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([208500., 181500., 223500., 140000., 250000.])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# You can write code in this cell\n",
    "iowa_model.predict(X.head())\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "94d0533e",
   "metadata": {
    "papermill": {
     "duration": 0.007265,
     "end_time": "2025-02-15T10:13:20.879513",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.872248",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "It's natural to ask how accurate the model's predictions will be and how you can improve that. That will be you're next step.\n",
    "\n",
    "# Keep Going\n",
    "\n",
    "You are ready for **[Model Validation](https://www.kaggle.com/dansbecker/model-validation).**\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ce5f35c",
   "metadata": {
    "papermill": {
     "duration": 0.007264,
     "end_time": "2025-02-15T10:13:20.894400",
     "exception": false,
     "start_time": "2025-02-15T10:13:20.887136",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "---\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "*Have questions or comments? Visit the [course discussion forum](https://www.kaggle.com/learn/intro-to-machine-learning/discussion) to chat with other learners.*"
   ]
  }
 ],
 "metadata": {
  "kaggle": {
   "accelerator": "none",
   "dataSources": [
    {
     "databundleVersionId": 111096,
     "sourceId": 10211,
     "sourceType": "competition"
    },
    {
     "datasetId": 11167,
     "sourceId": 15520,
     "sourceType": "datasetVersion"
    },
    {
     "datasetId": 2709,
     "sourceId": 38454,
     "sourceType": "datasetVersion"
    }
   ],
   "isGpuEnabled": false,
   "isInternetEnabled": false,
   "language": "python",
   "sourceType": "notebook"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 7.185427,
   "end_time": "2025-02-15T10:13:21.623257",
   "environment_variables": {},
   "exception": null,
   "input_path": "__notebook__.ipynb",
   "output_path": "__notebook__.ipynb",
   "parameters": {},
   "start_time": "2025-02-15T10:13:14.437830",
   "version": "2.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
